import { Directive, Input, TemplateRef, ViewContainerRef, OnInit } from '@angular/core';
import { Principal } from 'app/core/auth/principal.service';

@Directive({
    selector: '[appIsAuthenticated]'
})
export class IsAuthenticatedDirective implements OnInit{
    private authorities: string[];

    constructor(private principal: Principal, private templateRef: TemplateRef<any>, private viewContainerRef: ViewContainerRef) {}

    ngOnInit() {
        this.principal.identity().then(result => {
            this.viewContainerRef.clear();
            if (result) {
                this.viewContainerRef.createEmbeddedView(this.templateRef);
            }
        });
    }
}
